<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class MY_Controller extends CI_Controller {
	
    protected $_data = array();
	
    function __construct() {
        parent::__construct();
        $this->load->library('cart');
        $this->load->library('facebook', array(
            'appId' => '379162468853623',
            'secret' => 'bb52c489d2d42576acc18f069bdf85ec'
        ));
        if($this->logged_in()) {
            $this->load->vars('logged_in',  $this->logged_in());
        } else {
            $params = array(
              'scope' => 'read_stream, friends_likes, email',
              'redirect_uri' => base_url('login/facebook_login')
            );
            $loginUrl = $this->facebook->getLoginUrl($params);
            $this->load->vars('loginUrl',  $loginUrl);
        }
        $this->load->vars('numProduct', $this->cart->total_items());
        $menu = array();
        foreach(getMenuProCate(0) as $item) {
            $item->children = getMenuProCate($item->product_category_id);
            $menu[] = $item;
        }
        $this->load->vars('menuProductCate', $menu);
    }
    
    function logged_in() {
        $infoUser = $this->session->userdata("logged_in");
        if(!empty($infoUser)) {
            return $infoUser;
        }
        return false;
    }
    
    protected function _getInfoCart($edit = true) {
        $arrCart = $this->cart->contents();
        $this->load->model("products_model");
        $this->load->model("color_model");
        $this->load->model("size_model");
        if (!empty($arrCart)) {
            foreach ($arrCart as $key => $item) {
                $productInfo = $this->products_model->getProductFromId($item['id']);
                $arrCart[$key]['rowid'] = $item['rowid'];
                $arrCart[$key]['name'] = $productInfo->name;
                $arrCart[$key]['link'] = urlAlias($productInfo->name_alias."/item-{$productInfo->products_id}");
                $arrCart[$key]['quanlity'] = $item['qty'];
                $arrCart[$key]['sprice'] = $productInfo->sprice;
                $arrCart[$key]['color'] = $this->color_model->getColorById($item['option']['color']);
                $arrCart[$key]['size'] = $this->size_model->getSizeById($item['option']['size']);
                $arrCart[$key]['image'] = base_url("uploads/products/avatar/{$productInfo->image}");
            }
        }
        return $this->load->view("cart/thongtindonhang", array("arrCart" => $arrCart, 'edit' => $edit), true);
    }
}

/* End of file home.php */
/* Location: ./application/controllers/home.php */